<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<%@taglib prefix="priv" uri="/mytag/privilege"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>系统资源管理页面</title>
<script type="text/javascript" src="${path}/js/scripts/bootstart.js"></script>
</head>
<body style="width: 98%; height: 90%;">
	<div style="width: 100%;">
		<div class="mini-toolbar" style="border-bottom: 0; padding: 0px;"
			id="searchForm">
			<table style="width: 100%;">
				<tr>
					<td style="width: 100%;"><priv:priv-btn btnname="search">
								角色名称:
								<input class="mini-textbox" name="roleName"
								emptyText="请输入角色名，支持模糊查询" style="width: 200px;" />
							<a class="mini-button" onclick="griddata.Search()"
								iconCls="icon-search">查询</a>
							<a class="mini-button" iconCls="icon-undo"
								onclick="griddata.Clear()">重置</a>
										&nbsp;&nbsp;&nbsp;
								</priv:priv-btn> <priv:priv-btn btnname="add">
							<a class="mini-button" iconCls="icon-add"
								onclick="griddata.add()">增加</a>&nbsp;
							</priv:priv-btn> <priv:priv-btn btnname="edit">
							<a class="mini-button" iconCls="icon-edit"
								onclick="griddata.edit()">修改</a>&nbsp;
							</priv:priv-btn> <priv:priv-btn btnname="remove">
							<a class="mini-button" iconCls="icon-remove"
								onclick="griddata.remove()">删除</a>&nbsp;
							</priv:priv-btn> <priv:priv-btn btnname="setresource">
							<a class="mini-button" iconCls="icon-goto"
								onclick="griddata.showWindow()">分配资源</a>
						</priv:priv-btn></td>
				</tr>
			</table>
		</div>
	</div>
	<div id="roleGrid" class="mini-datagrid"
		style="width: 100%; height: 96%;" dataField="list"
		url="${path}/role/mgr/showList" pageSize="10" totalField="totalRecord"
		allowResize="false" idField="roleId" multiSelect="false"
		sizeList="[10,20,30]" sortField="roleId" sortOrder="desc">
		<div property="columns">
			<div type="checkcolumn"></div>
			<div field="roleName" width="60" headerAlign="center"
				allowSort="true">角色名称</div>
			<!-- <div field="roleType" width="60" headerAlign="center" allowSort="true" renderer="roleType">角色类型</div> -->
			<div field="addTime" width="80" headerAlign="center"
				dateFormat="yyyy-MM-dd HH:mm:ss">添加时间</div>
			<div field="roleDesc" width="120" headerAlign="center">角色描述</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="${path}/js/scripts/datagrid.js"></script>
<script type="text/javascript" src="${path}/js/scripts/utils.js"></script>
<script type="text/javascript" src="${path}/js/message.js"></script>
<script type="text/javascript">
	var doc = $(document);
	$(function() {
		$.grid.init({
			id : "roleGrid"
		});
		window.griddata = {}; //window對象下創建一個griddata對象

		griddata.add = function() {
			$.grid.add({
				url : "${path}/role/mgr/roleform",
				width : doc.width() * 0.5+"px",
				height : doc.height() * 0.6+"px",
				title : "角色添加"
			});
		};

		griddata.edit = function() {
			$.grid.edit({
				url : "${path}/role/mgr/roleform",
				title : "角色修改",
				formId : "roleForm",
				fieldId : "roleId",
				width : doc.width() * 0.5+"px",
				height : doc.height() * 0.6+"px",
				dataUrl : "${path}/role/mgr/showUpdate"
			});
		};

		griddata.remove = function() {
			$.grid.remove({
				url : "${path}/role/mgr/deleteRole",
				paramName : "key", //获取参数的参数名
				showMsg : true,//是否显示提示信息（删除成功与否返回信息）
				fldId : "roleId" //獲取選中列的主鍵值對應的列名
			});
		};

		griddata.showWindow = function() {
			var row = mini.get("roleGrid").getSelected();
			if (!row) {
				mini.alert("请选择分配资源的角色!");
				return;
			}

			$.grid.add({
				url : "${path}/role/mgr/roleresource?roleid=" + row.roleId,
				width : doc.width() * 1+"px",
				height : doc.height() * 1.2+"px",
				title : "资源分配—角色：" + row.roleName
			});
		};
		//清除查询条件
		griddata.Clear = function() {
			var SerachForm = new mini.Form("searchForm");
			SerachForm.reset();
		};
		//查询
		griddata.Search = function() {
			var SerachForm = new mini.Form("searchForm");
			var data = SerachForm.getData(true);
			//获取以Struts2对象封装格式的json对象 {"对象1.属性":"属性值","对象.属性2":"属性值"}
			var jsonObject = myutils.parseFormToJsonObject(data);
			$.grid.datagrid.load(jsonObject);
		};
	});
	function roleType(e) {
		if (e.value == 1) {
			return "系统管理员";
		} else if (e.value == 2) {
			return "校园代理";
		} else {
			return "其他";
		}
	}
</script>
</html>